package momo;

import java.io.File;
import javax.swing.filechooser.FileFilter;


/**
 * 
 * @author Mohamed.Mosa@lu.unisi.ch
 *
 * This class generates a filter which will only display the image types
 * I specify and this filter will only take affect when the filter is 
 * selected by the user in the file chooser window.
 */

public final class ImageFilter extends FileFilter {

	//This method allows Gif, Jpeg, Jpg, Png, Tif and 
	//Tiff types. It also accepts directories. 
	public final boolean accept(final File file) {
		if (file.isDirectory()) {
			return true;
		}

		String extension = Types.getExtension(file);
		if (extension != null) {
			if (extension.equals(Types.gif) ||
					extension.equals(Types.jpeg) ||
					extension.equals(Types.jpg) ||
					extension.equals(Types.png) ||
					extension.equals(Types.tif) ||
					extension.equals(Types.tiff)) {
				return true;
			} 
			else {
				return false;
			}
		}
		return false;
	}

	//Here we define the description of our filter
	public final String getDescription() {
		return "Show Images Only";
	}
}
